//
//  MineHeaderView.m
//  NewPro
//
//  Created by RYX on 2018/10/18.
//  Copyright © 2018年 何荧红. All rights reserved.
//

#import "MineHeaderView.h"

@implementation MineHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = BLUECOLOR;
        [self setup];
    }
    return self;
}

- (void)setup{
    
    UIImageView *bgView = [[UIImageView alloc] init];
    bgView.backgroundColor = BLUECOLOR;
    [self addSubview:bgView];
    self.bgView = bgView;
    
    UILabel *titleLa = [[UILabel alloc] init];
    titleLa.text = @"我的";
    titleLa.textAlignment = NSTextAlignmentCenter;
    titleLa.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:18];
    titleLa.textColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1];
    [self addSubview:titleLa];
    self.titleLa = titleLa;
    
    UIImageView *headIm = [[UIImageView alloc] init];
    headIm.image = [UIImage imageNamed:@"关于我们logo"];
    headIm.layer.cornerRadius = 1;
    headIm.layer.borderWidth = 2;
    headIm.layer.borderColor = [UIColor colorWithHexString:@"61BEEB"].CGColor;
    headIm.contentMode =  UIViewContentModeScaleAspectFill;
    headIm.clipsToBounds  = YES;
    
    [self addSubview:headIm];
    self.headIm = headIm;
    
    headIm.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTap)];
    [headIm addGestureRecognizer:tap];
    
    
    UIButton *titleBtn = [[UIButton alloc] init];
    [titleBtn setTitle:@"" forState:UIControlStateNormal];
    [titleBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    titleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
//    titleBtn.contentEdgeInsets = UIEdgeInsetsMake(0,0, 0, 0);
    titleBtn.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:16];
    [titleBtn addTarget:self action:@selector(onTitleBtn:) forControlEvents:UIControlEventTouchUpInside];
    titleBtn.titleLabel.textAlignment = NSTextAlignmentLeft;
    [self addSubview:titleBtn];
    self.titleBtn = titleBtn;
    
    UIButton *phoneBtn = [[UIButton alloc] init];
    phoneBtn.layer.cornerRadius = 11;
    phoneBtn.layer.borderWidth = 0.5;
    phoneBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    [phoneBtn setTitle:@"" forState:UIControlStateNormal];
    [phoneBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    phoneBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    phoneBtn.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    phoneBtn.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:12];
    [phoneBtn addTarget:self action:@selector(onPhoneBtn:) forControlEvents:UIControlEventTouchUpInside];
    phoneBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
    [self addSubview:phoneBtn];
    self.phoneBtn = phoneBtn;
    
    UIButton *codeBtn = [[UIButton alloc] init];
    [codeBtn setImage:[UIImage imageNamed:@"img_codeBtnBg"] forState:UIControlStateNormal];
    [codeBtn addTarget:self action:@selector(onCodeBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:codeBtn];
    self.codeBtn = codeBtn;
    
}

#pragma mark - 点击头像
- (void)onTap{
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(onHeaderIm)]) {
        
        [self.delegate onHeaderIm];
    }
}

#pragma mark - 标题
- (void)onTitleBtn:(UIButton *)btn{
    
    DLog(@"%@",btn.currentTitle);
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(onTitleBtn:)]) {
        
        [self.delegate onTitleBtn:btn];
    }
}

#pragma mark - 电话号码
- (void)onPhoneBtn:(UIButton *)btn{
    
    DLog(@"%@",btn.currentTitle);
    if (self.delegate && [self.delegate respondsToSelector:@selector(onPhoneBtn:)]) {
        
        [self.delegate onPhoneBtn:btn];
    }
}

#pragma mark - 二维码
- (void)onCodeBtn:(UIButton *)btn{
    
    DLog(@"二维码");
    if (self.delegate && [self.delegate respondsToSelector:@selector(onCodeBtn:)]) {
        
        [self.delegate onCodeBtn:btn];
    }
}

- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    self.bgView.frame = self.bounds;
    self.bgView.y -= ScreenHeight;
    self.bgView.height += ScreenHeight;
    
//    self.titleLa.x = (ScreenWidth - 50)/2;
//    self.titleLa.y = STATUS_BAR_HEIGHT + 10;
//    self.titleLa.width = 50;
//    self.titleLa.height = 20;
    
    self.headIm.x = 16;
    self.headIm.y = self.height - 75;
    self.headIm.width = 60;
    self.headIm.height = 60;
    
    self.titleBtn.x = CGRectGetMaxX(self.headIm.frame) + 17;
    self.titleBtn.y = self.headIm.y;
    self.titleBtn.width = 150;
    self.titleBtn.height = 25;
    
    self.phoneBtn.x = self.titleBtn.x;
    self.phoneBtn.y = CGRectGetMaxY(self.titleBtn.frame) + 5 ;
    self.phoneBtn.width = 94;
    self.phoneBtn.height = 22;
    
    self.codeBtn.width = 68;
    self.codeBtn.height = 58;
    self.codeBtn.y = self.headIm.centerY;
    self.codeBtn.x = ScreenWidth - 68 - 5;
    self.codeBtn.centerY = self.headIm.centerY;
}

@end
